import requests
import urllib3
import re

'''
1. 定位到2024必看片
2. 从2024必看片中提取到子页面的链接地址
3. 请求子页面的链接地址，拿到我们想要的下载地址...
'''
# 取消警告
requests.packages.urllib3.disable_warnings()
http = urllib3.PoolManager(num_pools=50)

headers = {
    "user-agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/131.0.0.0 Safari/537.36 Edg/131.0.0.0"
}

domain = "https://dytt89.com/"

# verify=False 不进行安全验证
resp = requests.get(domain, verify=False, headers=headers)
# 设置字符集与网页的一直，否则中文会乱码，网页的字符集可以在网页源代码的开头看到
resp.encoding = "gb2312"

#获取影片列表字符串
objUl = re.compile(r"2024必看热片.*?<ul>(?P<ul>.*?)</ul>",re.S)
obj2 = re.compile(r"<li><a href='/(?P<href>.*?)' title=\"(?P<title>.*?)\">")
obj3 = re.compile(r"a href=\"magnet(?P<href>.*?)\">")

childHrefList = []
# 定位需要信息的位置，获取字符串
it = objUl.finditer(resp.text)
for i in it:
    ul = i.group("ul").strip()

    # 从获取的字符串中获取有用信息
    it2 = obj2.finditer(ul)
    for ii in it2:
        url = domain+ii.group("href")
        childHrefList.append(url)


for i in childHrefList:
    resp2 = requests.get(i,verify=False,headers=headers)
    resp2.encoding = "gb2312"
    it3 = obj3.search(resp2.text)
    dic = it3.groupdict()
    dic['href'] = "magnet"+dic['href']
    print(dic)